#include "app_device.h"
#include "app_mqtt.h"
#include "app_pool.h"
#include "unistd.h"
#include "stdlib.h"
#include "app_bt.h"
#include "app_serial.h"
#include "signal.h"
#include "app_runner.h"

static int is_running=1;
static void app_runner_exit(int sig)
{
    is_running=0;
}

int app_runner_run()
{
    //0 注册终止信号  //ctrl+c  kill 
    signal(SIGTERM, app_runner_exit ); //kill 
    signal(SIGINT, app_runner_exit ) ; //ctrl+c 

    // 1 线程池
    app_pool_init(5);
    // 2 队列模块
    app_mqtt_init();
    // 3  设备初始化 
    device_t *device= app_device_init(DEVICE_FILE);
    // 4  设备配置初始化  串口 a蓝牙 
    app_device_start();
    app_serial_init(device);
    app_bt_init(device);

    while(is_running)
    {
        sleep(1);
    }
    //7 释放资源
    app_device_destroy();
    app_pool_close();
    app_mqtt_close();
    
    return 0;
}
